﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CacheHelper
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int time = int.Parse(txtTime.Text.Trim());
            CacheAssistantor cacher = new CacheAssistantor();
            cacher.Set(txtKey.Text.Trim(), txtValue.Text.Trim(), time);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int time = int.Parse(txtTime1.Text.Trim());
            CacheAssistantor cacher = new CacheAssistantor();
            cacher.Put(txtKey1.Text.Trim(), txtValue1.Text.Trim(), time);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            CacheAssistantor cacher = new CacheAssistantor();
            string value = cacher.Get<string>(txtKey.Text.Trim());
            ShowMessage(value);
        }

        int _msgLen;
        private void ShowMessage(string msg)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new Action<string>(ShowMessage), msg);
            }
            else
            {
                //if (_msgLen >= 300)
                //{
                //    txtMsg.Clear();
                //    //txtMessages.Text = "";
                //    _msgLen = 0;
                //}
                //LogHelper.WriteDebugLogEx("SysMonitor", msg);

                txtMsg.Text = txtMsg.Text + (DateTime.Now.ToString() + " " + msg + "\r\n");
                txtMsg.SelectionStart = txtMsg.Text.Length;
                txtMsg.ScrollToCaret();

                _msgLen++;

            }
        }

        private void ClearMessage()
        {
            txtMsg.Clear();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            CacheAssistantor cacher = new CacheAssistantor();
            string value = cacher.Get<string>(txtKey1.Text.Trim());
            ShowMessage(value);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
